$(document).ready(function() {
    xdh21()
});

function xdh21() {
    $.ajax({
        url: "http://localhost:8080/mark/selectCount?courseId=4",
        type: "GET",
        async: true,
        data: {},
        dataType: "json",
        success: function (data) {
            var ninety = data.data.markCount.ninety;
            var eighty = data.data.markCount.eighty;
            var seventy = data.data.markCount.seventy;
            var sixty = data.data.markCount.sixty;
            var ninety5 = data.data.markCount.ninety5;
            var eighty5 = data.data.markCount.eighty5;
            var seventy5 = data.data.markCount.seventy5;
            var sixty5 = data.data.markCount.sixty5;
            var fifty = data.data.markCount.fifty;
            var alls = ninety+eighty+seventy+sixty+ninety5+eighty5+eighty5+seventy5+seventy5+sixty5+fifty
            var ninety1 = ((data.data.markCount.ninety)/alls)*100;
            var eighty1 = ((data.data.markCount.eighty)/alls)*100;
            var seventy1= ((data.data.markCount.seventy)/alls)*100;
            var sixty1 = ((data.data.markCount.sixty)/alls)*100;
            var ninety51 = ((data.data.markCount.ninety5)/alls)*100;
            var eighty51 = ((data.data.markCount.eighty5)/alls)*100;
            var seventy51 = ((data.data.markCount.seventy5)/alls)*100;
            var sixty51 = ((data.data.markCount.sixty5)/alls)*100;
            var fifty1 = ((data.data.markCount.fifty)/alls)*100;


            var options = {
                title: {
                    text: "Desktop OS Market Share in 2017"
                },
                subtitles: [{
                    text: "As of November, 2017"
                }],
                animationEnabled: true,
                data: [{
                    type: "pie",
                    startAngle: 40,
                    toolTipContent: "<b>{label}</b>: {y}%",
                    showInLegend: "true",
                    legendText: "{label}",
                    indexLabelFontSize: 16,
                    indexLabel: "{label} - {y}%",
                    dataPoints: [
                        { y: fifty1.toFixed(2), label: "不及格" },
                        { y: sixty1.toFixed(2), label: "60-64" },
                        { y: sixty51.toFixed(2), label: "65-69" },
                        { y: seventy1.toFixed(2), label: "70-74" },
                        { y: seventy51.toFixed(2), label: "75-79" },
                        { y: eighty1.toFixed(2), label: "80-84" },
                        { y: eighty51.toFixed(2), label: "85-89" },
                        { y: ninety1.toFixed(2), label: "90-94" },
                        { y: ninety51.toFixed(2), label: "95-100" },

                    ]
                }]
            };
            $("#chartContainer").CanvasJSChart(options);
        },
        error: function () {
            layer.alert("暂无记录")
        }
    })
}
